/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.GUI.sidepanels;

import controller.commands.BasicCommand;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author Jelle
 */
public class TransferableArrayList extends ArrayList implements Transferable {

    final public static DataFlavor FLAVOR = new DataFlavor(ArrayList.class, "commands");
    static DataFlavor flavors[] = {FLAVOR};


    public TransferableArrayList() {}

    public DataFlavor[] getTransferDataFlavors() {
        return flavors;
    }

    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        Object returnObject;
        if (flavor.equals(flavors[0])) {
            Object userObject = getData();
            if (userObject == null) {
                returnObject = getData();
            } else {
                returnObject = userObject;
            }
        } else {
            throw new UnsupportedFlavorException(flavor);
        }
        return returnObject;
    }

    public boolean isDataFlavorSupported(DataFlavor flavor) {
        boolean returnValue = false;
        for (int i = 0, n = flavors.length; i < n; i++) {
            if (flavor.equals(flavors[i])) {
                returnValue = true;
                break;
            }
        }
        return returnValue;
    }

    /**
     * @return the data
     */
    public ArrayList<BasicCommand> getData() {
        return this;
    }

}